home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / VISCAFE.BIN / LabelButton.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-06-19  |  5.2 KB  |  279 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Rectangle;
  10.  
  11. public class LabelButton extends ButtonBase implements AlignStyle, BevelStyle {
  12.    public static final int INDENT_ZERO = 0;
  13.    public static final int INDENT_ONE = 1;
  14.    public static final int INDENT_TWO = 2;
  15.    protected String sLabelButton;
  16.    protected boolean showLabel;
  17.    private int alignStyle;
  18.    private int bevelStyle;
  19.    private Color color1;
  20.    private Color color2;
  21.    private Color textColor;
  22.    private Color borderedColor;
  23.    // $FF: renamed from: fm java.awt.FontMetrics
  24.    private FontMetrics field_0;
  25.    private int xTemp;
  26.    private int yTemp;
  27.    private int indent;
  28.    private int textWidth;
  29.    private int textAscent;
  30.    private int textHeight;
  31.    private boolean bOsFlag;
  32.  
  33.    public LabelButton() {
  34.       this("", 1, 1, Color.black, 0, true);
  35.    }
  36.  
  37.    public LabelButton(String var1, int var2, int var3) {
  38.       this(var1, var2, var3, Color.black, 0, true);
  39.    }
  40.  
  41.    public LabelButton(String var1, int var2, int var3, Color var4) {
  42.       this(var1, var2, var3, var4, 0, true);
  43.    }
  44.  
  45.    public LabelButton(String var1, int var2, int var3, int var4) {
  46.       this(var1, var2, var3, Color.black, var4, true);
  47.    }
  48.  
  49.    public LabelButton(String var1, int var2, int var3, Color var4, int var5, boolean var6) {
  50.       this.bOsFlag = false;
  51.       String var7 = System.getProperty("os.name");
  52.       if (!var7.startsWith("S") && !var7.startsWith("OSF")) {
  53.          this.bOsFlag = false;
  54.       } else {
  55.          this.bOsFlag = true;
  56.          this.setFont(new Font("Dialog", 0, 10));
  57.       }
  58.  
  59.       Font var8 = ((Component)this).getFont();
  60.       if (var8 == null) {
  61.          this.field_0 = ((Component)this).getFontMetrics(new Font("Dialog", 0, 12));
  62.       } else {
  63.          this.field_0 = ((Component)this).getFontMetrics(var8);
  64.       }
  65.  
  66.       this.setText(var1);
  67.       this.textColor = var4;
  68.       this.borderedColor = Color.black;
  69.       this.setBorderIndent(var5);
  70.       this.setAlignStyle(var2);
  71.       this.setBevelStyle(var3);
  72.       super.showFocus = true;
  73.       this.showLabel = var6;
  74.    }
  75.  
  76.    public void setAlignStyle(int var1) {
  77.       this.alignStyle = var1;
  78.    }
  79.  
  80.    public int getAlignStyle() {
  81.       return this.alignStyle;
  82.    }
  83.  
  84.    public void setBevelStyle(int var1) {
  85.       this.bevelStyle = var1;
  86.       switch (var1) {
  87.          case 0:
  88.             this.color1 = Color.black;
  89.             this.color2 = Color.gray;
  90.             return;
  91.          case 1:
  92.             this.color1 = Color.gray;
  93.             this.color2 = Color.black;
  94.             return;
  95.          case 2:
  96.             this.color1 = this.borderedColor;
  97.             this.color2 = this.borderedColor;
  98.             return;
  99.          default:
  100.             this.color1 = this.color2 = null;
  101.       }
  102.    }
  103.  
  104.    public int getBevelStyle() {
  105.       return this.bevelStyle;
  106.    }
  107.  
  108.    public void setBorderIndent(int var1) {
  109.       if (var1 < 0) {
  110.          this.indent = 0;
  111.       } else if (var1 > 2) {
  112.          this.indent = 2;
  113.       } else {
  114.          this.indent = var1;
  115.       }
  116.    }
  117.  
  118.    public int getBorderIndent() {
  119.       return this.indent;
  120.    }
  121.  
  122.    public void setBorderedColor(Color var1) {
  123.       this.borderedColor = var1;
  124.       if (this.bevelStyle == 2) {
  125.          this.color1 = var1;
  126.          this.color2 = var1;
  127.       }
  128.  
  129.       ((Component)this).invalidate();
  130.    }
  131.  
  132.    public void setText(String var1) {
  133.       Font var2 = ((Component)this).getFont();
  134.       if (var2 == null) {
  135.          this.field_0 = ((Component)this).getFontMetrics(new Font("Dialog", 0, 12));
  136.       } else {
  137.          this.field_0 = ((Component)this).getFontMetrics(var2);
  138.       }
  139.  
  140.       this.sLabelButton = var1;
  141.       this.textAscent = this.field_0.getAscent();
  142.       this.textHeight = this.field_0.getHeight();
  143.       this.textWidth = this.field_0.stringWidth(this.sLabelButton);
  144.    }
  145.  
  146.    public String getText() {
  147.       return this.sLabelButton;
  148.    }
  149.  
  150.    public void setTextColor(Color var1) {
  151.       this.textColor = var1;
  152.    }
  153.  
  154.    public Color getTextColor() {
  155.       return this.textColor;
  156.    }
  157.  
  158.    public void setShowLabel(boolean var1) {
  159.       this.showLabel = var1;
  160.    }
  161.  
  162.    public boolean getShowLabel() {
  163.       return this.showLabel;
  164.    }
  165.  
  166.    public void paint(Graphics var1) {
  167.       Dimension var2 = ((Component)this).size();
  168.       Rectangle var3 = ((Component)this).bounds();
  169.       this.yTemp = var3.height / 2 + this.textAscent / 2;
  170.       switch (this.alignStyle) {
  171.          case 0:
  172.             if (this.bevelStyle == 2) {
  173.                this.xTemp = 4;
  174.             } else {
  175.                this.xTemp = 8;
  176.             }
  177.             break;
  178.          case 1:
  179.             this.xTemp = (var3.width - this.textWidth) / 2;
  180.             break;
  181.          case 2:
  182.             this.xTemp = var3.width - this.textWidth;
  183.             if (this.bevelStyle == 2) {
  184.                this.xTemp -= 6;
  185.             } else {
  186.                this.xTemp -= 10;
  187.             }
  188.       }
  189.  
  190.       switch (this.bevelStyle) {
  191.          case 0:
  192.             super.pressed = !super.pressed;
  193.             super.paint(var1);
  194.             super.pressed = !super.pressed;
  195.             if (this.showLabel) {
  196.                var1.setColor(this.textColor);
  197.                if (super.pressed) {
  198.                   var1.drawString(this.sLabelButton, this.xTemp - super.pressedAdjustment, this.yTemp - super.pressedAdjustment);
  199.                   return;
  200.                }
  201.  
  202.                var1.drawString(this.sLabelButton, this.xTemp, this.yTemp);
  203.                return;
  204.             }
  205.             break;
  206.          case 1:
  207.             super.paint(var1);
  208.             if (this.showLabel) {
  209.                var1.setColor(this.textColor);
  210.                if (super.pressed) {
  211.                   var1.drawString(this.sLabelButton, this.xTemp + super.pressedAdjustment, this.yTemp + super.pressedAdjustment);
  212.                   return;
  213.                }
  214.  
  215.                var1.drawString(this.sLabelButton, this.xTemp, this.yTemp);
  216.                return;
  217.             }
  218.             break;
  219.          case 2:
  220.             var1.setColor(((Component)this).getForeground());
  221.             var1.drawRect(this.indent, this.indent, var2.width - 1 - this.indent - this.indent, var2.height - 1 - this.indent - this.indent);
  222.          case 3:
  223.             if (this.showLabel) {
  224.                var1.setColor(this.textColor);
  225.                var1.drawString(this.sLabelButton, this.xTemp, this.yTemp);
  226.             }
  227.  
  228.             if (super.showInfoTip && super.doInfoTip) {
  229.                ((ButtonBase)this).drawInfoTip();
  230.             }
  231.       }
  232.  
  233.    }
  234.  
  235.    public void setFont(Font var1) {
  236.       super.setFont(var1);
  237.       this.field_0 = ((Component)this).getFontMetrics(((Component)this).getFont());
  238.       this.textAscent = this.field_0.getAscent();
  239.       this.textHeight = this.field_0.getHeight();
  240.       this.textWidth = this.field_0.stringWidth(this.sLabelButton);
  241.    }
  242.  
  243.    public Dimension preferredSize() {
  244.       Dimension var1 = ((Component)this).size();
  245.       Dimension var2 = this.minimumSize();
  246.       return new Dimension(Math.max(var1.width, var2.width), Math.max(var1.height, var2.height));
  247.    }
  248.  
  249.    public Dimension minimumSize() {
  250.       Dimension var1 = new Dimension(18, 10);
  251.       Font var2 = ((Component)this).getFont();
  252.       if (var2 == null) {
  253.          if (this.bOsFlag) {
  254.             var1.height = 29;
  255.          }
  256.       } else {
  257.          var1.width = this.textWidth + 18;
  258.          var1.height = this.textHeight + 10;
  259.          if (this.bOsFlag && var1.height < 29) {
  260.             var1.height = 29;
  261.          }
  262.       }
  263.  
  264.       return var1;
  265.    }
  266.  
  267.    public synchronized void reshape(int var1, int var2, int var3, int var4) {
  268.       super.reshape(var1, var2, var3, var4);
  269.       if (!((Component)this).isValid()) {
  270.          ((Component)this).repaint();
  271.       }
  272.  
  273.    }
  274.  
  275.    public void update(Graphics var1) {
  276.       this.paint(var1);
  277.    }
  278. }
  279.